package com.example.spindrift.service;

import com.example.spindrift.dao.SysSingMapper;
import com.example.spindrift.models.SysSing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SingService {
    @Autowired
    SysSingMapper sysSingMapper;

    public List<SysSing> getSingByName(String singName){
        return sysSingMapper.getSingByUserName(singName);
    }

    public List<SysSing> getAllSing() {
        return sysSingMapper.getAllSing();
    }

    public SysSing getSingById(Integer singId) {
        return sysSingMapper.getSingById(singId);
    }

    public List<SysSing> searchSing(String keyword) {
        return sysSingMapper.searchSing(keyword);
    }

    public List<SysSing> getSingByUserName(String singName) {
        return sysSingMapper.getSingByUserName(singName);
    }

    /**
     * 添加一条歌手信息，并返回主键ID
     * @param sing 歌手
     * @return 刚插入的歌手信息ID
     */
    public Integer insertSing(SysSing sing){
        List<SysSing> dt = sysSingMapper.getSingByUserName(sing.sing_name);
        if( dt != null && dt.size() >= 1){
            return dt.get(0).sing_id;
        }else{
            int count = sysSingMapper.insertSing(sing);
            int key = sing.getSing_id();
            if(count >= 0){
                return key;
            }
            return -1;
        }
    }

    public Integer updateSing(SysSing sing) {
        return sysSingMapper.updateSing(sing);
    }

    public Integer deleteSing(Integer singId) {
        return sysSingMapper.deleteSing(singId);
    }
}
